import Sky from './scripts/Sky.js'
import Land from './scripts/Land.js'
import Bird from './scripts/Bird.js'

const sky = new Sky()
const land = new Land()
const bird = new Bird()

let status = false
let timer = null
const pauseDom = document.querySelector('.pause')
pauseDom.innerText = '按回车开始游戏'

document.addEventListener('keydown', (e) => {
  if (e.key === ' ') {
    bird.jump()
  } else if (e.code === 'Enter')  {
    if (!status) {
      pauseDom.style.display = 'none'
      bird.wingWaveStart();
      timer = setInterval(() => {
        sky.move(16 / 1000)
        land.move(16 / 1000)
        bird.move(16 / 1000)
      }, 16)
    } else {
      pauseDom.innerText = '游戏已暂停'
      pauseDom.style.display = 'block'
      bird.wingWavePause()
      clearInterval(timer)
      timer = null
    }
    status = !status
  }
})
